package com.job.project.controller;

import com.job.project.service.AnimalService;
import com.job.project.utils.RestResponse;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @Author 王博
 * @DateTime 2024-08-19 14:58
 */
@RestController
public class AnimalController {
//    @Resource
//    private List<AnimalService> animalServiceList;//AnimalService所有子类的实例对象都会被注入到 animalServiceList中
    @Resource
    private Map<String,AnimalService> animalServiceMap;//AnimalService所有子类的实例对象都会被注入到 animalServiceMap中，key为beanName

   /* @GetMapping("/animal/eat")
    public RestResponse eat(){
        for (AnimalService animalService : animalServiceList) {
            animalService.eat();
        }
        return RestResponse.ok();
    }*/

    @GetMapping("/animal/eat/special")
    public RestResponse eatAsync(@RequestParam("category")String category){
        AnimalService animalService = animalServiceMap.get(category);
        animalService.eat();
        return RestResponse.ok();
    }
}
